package com.lin.mr.maizilaundry.myadapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lin.mr.maizilaundry.R;
import com.lin.mr.maizilaundry.entity.Means;
import com.lin.mr.maizilaundry.utils.VolleyUtils;

import java.util.List;

/**
 * Created by lenovog on 2016/8/18.
 */
public class MeansAdapter extends BaseAdapter{
    private Context context;
    private List<Means.MeansInfoBean> list;

    public MeansAdapter(Context context, List<Means.MeansInfoBean> list) {
        this.context = context;
        this.list = list;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<Means.MeansInfoBean> getList() {
        return list;
    }

    public void setList(List<Means.MeansInfoBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.means_item,null);
            holder.mean_text = (TextView) convertView.findViewById(R.id.means_text);
            holder.means_image = (ImageView) convertView.findViewById(R.id.means_image);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        Means.MeansInfoBean meansInfoBean = list.get(position);
        VolleyUtils.loadImage(meansInfoBean.getImageMeans(),
                holder.means_image,R.mipmap.ic_launcher,R.mipmap.error);
        holder.mean_text.setText(meansInfoBean.getTextMeans());
        return convertView;
    }

    public static class ViewHolder{
        private TextView mean_text;
        private ImageView means_image;
    }
}
